using System;
using System.Web.Mvc;

using $SolutionName$.Business.Validations.Base;

namespace $safeprojectname$.Utilities
{
    public class ModelStateDecorator : IValidationRules
    {
        private ModelStateDictionary _modelState;

        public ModelStateDecorator(ModelStateDictionary modelState)
        {
            _modelState = modelState;
        }

        public void Add(string key, string errorMessage)
        {
			if (_modelState.ContainsKey(key))
                _modelState.Remove(key);

            _modelState.AddModelError(key, errorMessage);
        }

        public bool IsValid
        {
            get { return _modelState.IsValid; }
        }
	}
}